/**
 * @param {number[]} maxHeights
 * @return {number}
 */
var maximumSumOfHeights = function (maxHeights) {
    let ans = 0
    let tempMax = 0
    for (let i = 0; i < maxHeights.length; i++) {
        let j = i - 1, k = i, curMax = maxHeights[i]
        while (j >= 0) {
            if (maxHeights[j] <= curMax) {
                tempMax += maxHeights[j]
                curMax = maxHeights[j]
            } else {
                tempMax += curMax
            }
            j--
        }
        curMax = maxHeights[i]
        while (k < maxHeights.length - 1) {
            if (curMax >= maxHeights[k + 1]) {
                tempMax += maxHeights[k + 1]
                curMax = maxHeights[k + 1]
            } else {
                tempMax +=curMax
            }
            k++
        }
        tempMax += maxHeights[i]
        console.log(tempMax);
        if(tempMax > ans) {
            ans = tempMax
        }
        tempMax = 0
    }
    return ans
};
console.log(maximumSumOfHeights([6,5,3,9,2,7]));